package dao;

import java.io.File;

import com.db4o.Db4o;
import com.db4o.ObjectContainer;

/**
 * 
 * @author Csaba Tarkanyi
 * 
 */
public class DaoManager {
	/*
	 * By using Singleton Pattern, every time the DaoManager being called we
	 * gets always the same Object.
	 */
	private static DaoManager instance = new DaoManager();

	private ObjectContainer db;

	// The Constructer is private.
	private DaoManager() {
	}

	public static DaoManager getInstance() {
		return instance;
	}

	/**
	 * Sets the updateDepth for the database if it is not opened yet (this is
	 * for tell to the database how deep it should gets the data from the file)
	 * and opens the database file.
	 * 
	 * @author Csaba Tarkanyi
	 */
	public ObjectContainer getObjectContainer() {
		if (db == null) {
			new File("db.db4o").delete();
			Db4o.configure().updateDepth(20);
			Db4o.configure().activationDepth(20);
			db = Db4o.openFile("db.db4o");
		}
		return db;
	}
}
